package com.example.textviewactivity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.example.textviewactivity.Fragment.HelpFragment;
import com.example.textviewactivity.Fragment.MimeFragment;
import com.example.textviewactivity.Fragment.SetFragment;
import com.example.textviewactivity.Fragment.UserFragment;
import com.example.textviewactivity.pojo.User;

import java.io.Serializable;

public class LoginSuccessActivity extends AppCompatActivity implements RadioGroup.OnCheckedChangeListener {
    TextView tv;
    String like="";
    User user;
    FragmentTransaction ft;
    FragmentManager fm;
    RadioGroup rb;
    UserFragment userFragment;
    SetFragment setFragment;
    HelpFragment helpFragment;
    MimeFragment mimeFragment;
    private static final String TAG = "LoginSuccessActivity";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login_success);
        tv=findViewById(R.id.tv);
        rb=findViewById(R.id.rb);
        rb.setOnCheckedChangeListener(this);
        userFragment=new UserFragment();
        setFragment=new SetFragment();
        helpFragment=new HelpFragment();
        mimeFragment=new MimeFragment();

        tv.setText("主页");
        fm=getSupportFragmentManager();
        ft=fm.beginTransaction();
        ft.add(R.id.fragment,userFragment);
        ft.commit();

        Intent intent=getIntent();
        user = (User) intent.getSerializableExtra("user");
        Log.d(TAG, "onCreate: "+user);
    }

    public User send(){
        return user;
    }

    @Override
    public void onCheckedChanged(RadioGroup radioGroup, int i) {
        ft=fm.beginTransaction();
        switch (rb.getCheckedRadioButtonId()){
            case R.id.home:
                ft.replace(R.id.fragment,userFragment);
                tv.setText("主页");
                break;
            case R.id.set:
                ft.replace(R.id.fragment,setFragment);
                tv.setText("设置");
                break;
            case R.id.help:
                ft.replace(R.id.fragment,helpFragment);
                tv.setText("帮助");
                break;
            case R.id.mime:
                ft.replace(R.id.fragment,mimeFragment);
                tv.setText("我的");
                break;
        }
        ft.commit();
    }
}
